package nz.ac.massey.cs.se400_2013.ass3.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class Toolbar extends JMenuBar{

	private static final long serialVersionUID = 1L;
	JMenuItem exit = new JMenuItem("exit");
	JMenuItem delete = new JMenuItem("delete");
	JMenuItem save = new JMenuItem("save");
	JMenuItem newPaper = new JMenuItem("new paper");
	JMenuItem newCourse = new JMenuItem("new course");
	JMenuItem newStudent = new JMenuItem("new student");
	
	public Toolbar(){
		this.add(exit);
		this.add(save);
		this.add(delete);
		this.add(newPaper);
		this.add(newCourse);
		this.add(newStudent);
		
		this.exit.addActionListener(new ExitHandler());
		this.newStudent.setEnabled(false);
		this.newPaper.setEnabled(false);
		this.delete.setEnabled(false);
		this.save.setEnabled(false);
		
	}
	
	public void setStudentEnabled(boolean visible){
		this.newStudent.setEnabled(visible);
	}
	
	public void setPaperEnabled(boolean visible){
		this.newPaper.setEnabled(visible);
	}
	
	public void setSaveEnabled(boolean visible){
		this.save.setEnabled(visible);
	}
	
	public void setDeleteEnabled(boolean visible){
		this.delete.setEnabled(visible);
	}
	
	class ExitHandler implements ActionListener{
		public void actionPerformed(ActionEvent arg0) {
			System.exit(0);
			
		}
	}
	
	public void addPaperHandler(Handler handler){
		this.newPaper.addActionListener(handler);
	}
	
	public void addCourseHandler(Handler handler){
		this.newCourse.addActionListener(handler);
	}
	
	public void addStudentHandler(Handler handler){
		this.newStudent.addActionListener(handler);
	}
	
	public void addSaveHandler(Handler handler){
		this.save.addActionListener(handler);
	}
	
	public void addDeleteHandler(Handler handler){
		this.delete.addActionListener(handler);
	}
	
	public void removeSaveHandler(Handler handler){
		this.save.removeActionListener(handler);
	}
	
}
